package com.xinlianshiye.im.dao.impl;

import com.xinlianshiye.im.dao.BaseRepository;
import com.xinlianshiye.im.dao.custom.UserDaoCustom;
import com.xinlianshiye.im.bean.QFriend;
import com.xinlianshiye.im.bean.QRecord;
import com.xinlianshiye.im.bean.User;

import java.util.List;

public class UserDaoImpl extends BaseRepository implements UserDaoCustom {

    @Override
    public List<User> findAllFollower(Integer userId) {
        QFriend friend = QFriend.friend1;
        return queryFactory.select(friend.user).from(friend)
                .where(friend.friend.id.eq(userId))
                .where(friend.user.accountStatus.eq(User.AccountStatusEnum.Normal))
                .fetch();
    }

    @Override
    public List<User> findContactByName(Integer userId, String name) {
        QRecord record = QRecord.record;
        return queryFactory
                .select(record.other)
                .from(record)
                .where(record.deleted.eq(false))
                .where(record.owner.id.eq(userId))
                .groupBy(record.otherId)
                .fetch();
    }
}
